package org.hu.vhr.controller.Sys.basic;

import org.hu.vhr.model.Position;
import org.hu.vhr.model.RespBean;
import org.hu.vhr.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/basic/pos")
public class PositionController {
    @Autowired
    PositionService positionService;

    /**
     * 查询全部职位
     * @return
     */
    @GetMapping("/")
    public List<Position> getAllPositions(){
        return positionService.getAllPositions();
    }

    /**
     * 新增职位
     * @param position
     * @return
     */
    @PostMapping("/insert")
    public RespBean insertPosition(@RequestBody Position position){
        System.out.println(position.getName());
        if(positionService.insertPosition(position)==1){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");
    }

    /**
     * 编辑职位
     * @param position
     * @return
     */
    @PutMapping("/update")
    public RespBean updatePosition(@RequestBody Position position){
        if(positionService.updatePosition(position)==1){
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }

    /**
     * 删除职位
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public RespBean deletePositionById(@PathVariable Integer id){
        if(positionService.deletePosition(id)==1){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    /**
     * 批量删除职位
     * @param ids
     * @return
     */
    @DeleteMapping("/")
    public RespBean deletPositions(Integer[] ids){
        if(positionService.deletePositions(ids)==ids.length){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }
}
